const chineseToPinyin = require('chinese-to-pinyin');
const Cache = require('node-cache');

const cache = new Cache({
    stdTTL: 300,
    checkperiod: 300,
});

module.exports = app => {   
    

    return class Pinyin extends app.Service {
        
        convertFullPinyin(str) {
            let cached = cache.get(str);
            if (cached === undefined) {
                cached = chineseToPinyin(str, { filterChinese:true, noTone: true });
                cache.set(str, cached);
            }
            return cached;
        }
    }
};
  